<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>季度数据柱形图</title>
    <style>
        #chart {
            display: flex;
            justify-content: center;
            align-items: flex-end;
            height: 300px;
            gap: 20px;
        }
        .bar {
            width: 50px;
            background-color: #007BFF;
            position: relative;
        }

        .bar span {
            position: absolute;
            top: -20px;
            left: 50%;
            transform: translateX(-50%);
        }
        .bar::after {
            content: attr(data-quarter);
            position: absolute;
            bottom: -20px;
            left: 50%;
            transform: translateX(-50%);
        }
    </style>
</head>
<body>
    <button onclick="generateChart()">生成柱形图</button>
    <div id="chart"></div>
    <script>
        function generateChart() {
            let data = [];
            for (let i = 1; i <= 4; i++) {
                let input = prompt(`请输入第 ${i} 季度的数据：`);
                data.push(Number(input));
            }
            let chart = document.getElementById('chart');
            chart.innerHTML = '';
            data.forEach((value, index) => {
                let bar = document.createElement('div');
                bar.classList.add('bar');
                bar.style.height = `${value}px`;
                bar.setAttribute('data-quarter', `第 ${index + 1} 季度`);
                let span = document.createElement('span');
                span.textContent = value;
                bar.appendChild(span);
                chart.appendChild(bar);
            });
        }
    </script>
</body>
</html>